package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class HJ42_不爱施肥的小布 {
  public static void main(String[] args) throws FileNotFoundException {
    Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/42.txt"));
    int N = in.nextInt();
    int M = in.nextInt();
    int[] fields = new int[N];
    for (int i = 0; i < N; i++) {
      fields[i] = in.nextInt();
    }
    Arrays.sort(fields);
    int left = fields[0], right = fields[N - 1];
    int mid = 0;
    while (left <= right) {
      mid = left + ((right - left) >> 1);
      if (needDays(fields, mid) < M) {
        right = mid - 1;
      } else if (needDays(fields, mid) == M) {
        right = mid - 1;
      } else if (needDays(fields, mid) > M) {
        left = mid + 1;
      }
    }
    if (left > fields[N - 1]) {
      System.out.println(-1);
    } else {
      System.out.println(left);
    }
  }

  static int needDays(int[] fields, int nengxiao) {
    int res = 0;
    for (int field : fields) {
      if (field % nengxiao == 0) {
        res += (field / nengxiao);
      } else {
        res += (field / nengxiao) + 1;
      }
    }
    return res;
  }
}
